package nothing.model;

import org.appfuse.model.BaseObject;
import java.sql.Blob;
import java.sql.Date;
import org.appfuse.model.User;
import javax.persistence.*;

@Entity @Table(name="diary")
public class Diary extends BaseObject {
    private Long id;
    private Date when;
    private Recipe recipe;
    private User user;
    public Diary(){}
    
    public Diary(Date when, Recipe recipe, User user){
        this.setWhen(when);
        this.setRecipe(recipe);
        this.setUser(user);
    }    
    @Id @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="user_id",referencedColumnName="id",nullable=false, insertable=true, updatable=true)     
    public User getUser() {
        return user;
    }
    public void setUser(User user) {
        this.user = user;
    }
    @Column(name="dtm", length=19)
	public Date getWhen() {
		return when;
	}
    public void setWhen(Date when) {
        this.when = when;
    }
    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="recipe_id",referencedColumnName="id",nullable=false, insertable=true, updatable=true)     
    public Recipe getRecipe() {
        return recipe;
    }
    public void setRecipe(Recipe recipe) {
        this.recipe = recipe;
    }
	public String toString() {
        return "Cooked{" +
        		"id="+id+", "+
        		"when="+when+", "+
        		"recipe="+recipe+", "+
                "}";
    }
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((recipe == null) ? 0 : recipe.hashCode());
		result = prime * result + ((when == null) ? 0 : when.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (getClass() != obj.getClass())
			return false;
		Diary other = (Diary) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (recipe == null) {
			if (other.recipe != null)
				return false;
		} else if (!recipe.equals(other.recipe))
			return false;
		if (when == null) {
			if (other.when != null)
				return false;
		} else if (!when.equals(other.when))
			return false;
		return true;
	}
	
}
